package com.ems.controller;

import com.ems.config.LogPointer;
import com.ems.remote.components.PcsRequestStrategy;
import com.ems.service.IPcsService;
import com.ems.vo.BaseResult;
import com.ems.vo.DeviceVo;
import com.ems.vo.PcsVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * PCS数据 前端控制器
 * </p>
 * @author WuZH
 * @since 2024-04-23
 */
@RestController
@RequestMapping ("/pcs")
@CrossOrigin (value = "*", maxAge = 3600)
public class PcsController {

    @Resource
    private IPcsService iPcsService;
    @Resource
    private PcsRequestStrategy pcsRequestStrategy;

    @RequestMapping ("querySingle")
    public BaseResult querySingle (@RequestBody PcsVo pcsVo) {
        pcsVo = iPcsService.querySingle ( pcsVo );
        return BaseResult.success ( pcsVo );
    }

    @RequestMapping ("queryList")
    public BaseResult queryList (@RequestBody PcsVo pcsVo) {
        List<PcsVo> pcsVos = iPcsService.queryList ( pcsVo );
        return BaseResult.success ( pcsVos );
    }

    @RequestMapping ("openClose")
    @LogPointer ("控制PCS开关机")
    public BaseResult openClose (@RequestBody PcsVo pcsVo) {
        pcsRequestStrategy.request ( pcsVo );
        return BaseResult.success ();
    }

    @RequestMapping ("alarmRest")
    @LogPointer ("故障复位")
    public BaseResult alarmRest (@RequestBody PcsVo pcsVo) {
        pcsRequestStrategy.alarmRest ( pcsVo );
        return BaseResult.success ();
    }

    @RequestMapping ("offGird")
    @LogPointer ("离网模式设置")
    public BaseResult offGird (@RequestBody PcsVo pcsVo) {
        pcsRequestStrategy.offGird ( pcsVo );
        return BaseResult.success ();
    }

    @RequestMapping ("setChargeDisPower")
    @LogPointer ("设置PCS充放电功率")
    public BaseResult setChargeDisPower (@RequestBody DeviceVo deviceVo) {
        pcsRequestStrategy.setChargeDisPower ( deviceVo );
        return BaseResult.success ();
    }

}
